from django.utils.safestring import mark_safe
from django.db import models


gender_choices = (
    (1, "男"),
    (2," 女")
)
college_choices = (
    ("ND","能源与动力工程学院"),
    ("JZ","计算机与人工智能学院"),
    ("SG","数字经济与管理学院"),
    ("RW","人文学院"),
    ("JY","教育学院"),
    ("YS","艺术学院"),
    ("CM","传媒学院"),
)
class StudentInfo(models.Model):
    """
    学生信息表
    """
    学号 = models.CharField(verbose_name="学号",max_length=16,blank=True, null=True)
    姓名 = models.CharField(verbose_name="姓名",max_length=16,blank=True, null=True)
    性别 = models.CharField(verbose_name="性别",max_length=8,blank=True, null=True)
    上课院系 = models.TextField(verbose_name="上课院系",blank=True, null=True)
    专业号 = models.CharField(verbose_name="专业号",max_length=8,blank=True, null=True)
    专业名称 = models.TextField(verbose_name="专业名称",blank=True, null=True)
    班级 = models.TextField(verbose_name="班级",blank=True, null=True)
    学制 = models.SmallIntegerField(verbose_name="学制",blank=True, null=True)
    当前所在级 = models.CharField(verbose_name="当前所在级",max_length=6,blank=True, null=True)
    出生日期 = models.CharField(verbose_name="出生日期",max_length=8,blank=True, null=True)
    身份证件号 = models.CharField(verbose_name="身份证件号",max_length=18,blank=True, null=True)
    考生号 = models.CharField(verbose_name="考生号",max_length=32,blank=True, null=True)
    入学年份 = models.CharField(verbose_name="入学年份",max_length=8,blank=True, null=True)
    在校状态 = models.CharField(verbose_name="在校状态",max_length=8,blank=True, null=True)
    学籍状态 = models.CharField(verbose_name="学籍状态",max_length=8,blank=True, null=True)
    学生当前状态 = models.CharField(verbose_name="学生当前状态",max_length=8,blank=True, null=True)
    入学日期 = models.CharField(verbose_name="入学日期",max_length=8,blank=True, null=True)
    培养层次 = models.CharField(verbose_name="培养层次",max_length=8,blank=True, null=True)
    民族 = models.CharField(verbose_name="民族",max_length=8,blank=True, null=True)

class StudentDetail(models.Model):
    学号 = models.CharField(verbose_name="学号",max_length=64,blank=True,null=True)
    姓名 = models.CharField(verbose_name="姓名",max_length=16)
    性别 = models.SmallIntegerField(verbose_name="性别",choices=gender_choices)
    学院 = models.CharField(verbose_name="学院",max_length=16,blank=True,null=True)
    联系电话 = models.CharField(verbose_name="联系电话",max_length=128,blank=True,null=True)
    宿舍号 = models.CharField(verbose_name="宿舍号",max_length=32,blank=True,null=True)
    家庭住址 = models.CharField(verbose_name="家庭住址",max_length=128,blank=True,null=True)
    籍贯 = models.CharField(verbose_name="籍贯",max_length=128,blank=True,null=True)

class College(models.Model):
    """
    学院表
    """
    college = models.CharField(verbose_name="学院",max_length=2,choices=college_choices)

class Counselor(models.Model):
    """
    辅导员表
    """
    name = models.CharField(verbose_name="姓名",max_length=8)
    gender = models.SmallIntegerField(verbose_name="性别",choices=gender_choices)
    # 级联删除：on_delete=models.CASCADE
    # 置空：on_delete=models.SET_NULL
    college = models.ForeignKey(verbose_name="所在学院",to="College",to_field="id",null=True,blank=True,on_delete=models.SET_NULL)
    birthdate = models.DateField(verbose_name="出生年月",blank=True,null=True)
    nationality = models.CharField(verbose_name="民族",max_length=16,blank=True,null=True)
    political_affiliation = models.CharField(verbose_name="政治面貌",max_length=8,blank=True,null=True)
    graduate_school = models.CharField(verbose_name="毕业院校",max_length=32,blank=True,null=True)
    major = models.CharField(verbose_name="所学妆业",max_length=32,blank=True,null=True)
    degree = models.CharField(verbose_name="学历",max_length=16,blank=True,null=True)
    enter_time = models.CharField(verbose_name="入职时间",max_length=16,blank=True,null=True)
    phone_number = models.CharField(verbose_name="手机号码",max_length=16,blank=True,null=True)

category_choices=(
    (1,"本校职工"),
    (2,"外聘老师"),
    (3,"合作单位")
)
permission_choices = (
    (True,mark_safe('<span class="glyphicon glyphicon-ok" aria-hidden="true" style="color:green"></span>')),
    (False,mark_safe('<span class="glyphicon glyphicon-remove" aria-hidden="true" style="color:red"></span>'))
)

class CarInfo(models.Model):
    """
    车辆信息表
    """
    department = models.CharField(verbose_name="部门",max_length=16)
    dep_detail = models.CharField(verbose_name="所在单位",max_length=16,blank=True,null=True,default="--")
    name = models.CharField(verbose_name="姓名",max_length=16)
    car_number = models.CharField(verbose_name="车牌号",max_length=16,unique=True)
    phone_number = models.CharField(verbose_name="电话号码",max_length=11)
    south_gate = models.BooleanField(verbose_name="南门权限",blank=True,null=True,choices=permission_choices)
    east_gate = models.BooleanField(verbose_name="东门权限",blank=True,null=True,choices=permission_choices)
    west_gate = models.BooleanField(verbose_name="西门权限",blank=True,null=True,choices=permission_choices)
    southeast_gate = models.BooleanField(verbose_name="东南门门权限",blank=True,null=True,choices=permission_choices)
    create_date = models.DateField(verbose_name="开通时间",auto_now_add=True)
    due_date = models.DateField(verbose_name="到期时间")
    category = models.SmallIntegerField(verbose_name="人员类别",choices=category_choices)
    notes = models.CharField(verbose_name="备注",max_length=16,blank=True,null=True,default='--')

reason_choice = (
    (1,'变更车辆'),
    (2,'员工离职'),
    (3,'权限到期'),
    (4,'违规取消'),
)

class CancelCarInfo(models.Model):
    department = models.CharField(verbose_name="部门",max_length=16)
    dep_detail = models.CharField(verbose_name="所在单位",max_length=16,blank=True,null=True,default="--")
    name = models.CharField(verbose_name="姓名",max_length=16)
    car_number = models.CharField(verbose_name="车牌号",max_length=16)
    phone_number = models.CharField(verbose_name="电话号码",max_length=11)
    cancel_date = models.DateField(verbose_name="取消日期",auto_now_add=True)
    category = models.SmallIntegerField(verbose_name="人员类别",choices=category_choices)
    reason = models.SmallIntegerField(verbose_name="取消原因",choices=reason_choice)

class Admin(models.Model):
    username = models.CharField(verbose_name="用户姓名",max_length=32)
    password = models.CharField(verbose_name="密码",max_length=64)
